﻿using System.Linq;
using WeBlog.Interfaces;
using WeBlog.Models;
using WeBlog.Repositories;

namespace WeBlog.Models
{
    public class SearchViewModel : GridModel<Post>
    {
        private PostRepository _postRepository;

        public SearchViewModel(GridSettings settings, IUnitOfWork unitOfWork ) :
            base(settings)
        {
            _postRepository = new PostRepository(unitOfWork);
            settings.DefaultSortColumn = "Title";
        }

        public string Query { get; set; }

        public override IQueryable<Post> GetSuperSet()
        {
            return _postRepository.PublishedPosts()
                .Where(x => x.Title.Contains(Query) ||
                            x.Content.Contains(Query));
        }
    }
}